package cn.wyu.blogrest;

import cn.wyu.blogrest.repository.AuthRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class BlogrestApplication extends WebMvcConfigurationSupport {

	@Autowired
	private  AuthInterceptor authInterceptor;

	public static void main(String[] args) {
		SpringApplication.run(BlogrestApplication.class, args);
	}


	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//对所有的请求进行拦截
		registry.addInterceptor(authInterceptor).addPathPatterns("/**").excludePathPatterns("/error/**").
						excludePathPatterns("/user/init").excludePathPatterns("/user/auth");
	}

//	@Bean
//	public  AuthInterceptor authInterceptor(){
//		return  new AuthInterceptor();
//	}


	/**
	 * 下面这段拦截器的配置，好像不适用于springboot了
	 */

//	@Bean
//	public WebMvcConfigurer configurer(){
//		return  new WebMvcConfigurer() {
//			@Override
//			public void addInterceptors(InterceptorRegistry registry) {
//				registry.addInterceptor(getAuthInterceptor()).addPathPatterns("/**").excludePathPatterns("/error/**").
//						excludePathPatterns("/user/init").excludePathPatterns("/user/auth");
//			}
//		};
//	}
//
//	@Bean
//	public AuthInterceptor getAuthInterceptor(){
//		return new AuthInterceptor();
//	}
}
